$(function () {
    $("#page").load('/back/page.html')
    findAll()
});

function findAll() {
    let data = {};
    data.newsType=$("#newsType").val();
    data.newsTitle=$("#newsTitle").val();
    data.publisher=$("#publisher").val();
    data.startReleaseTime=$("#startReleaseTime").val();
    data.endReleaseTime=$("#endReleaseTime").val();
    data.pageSize = $.trim($("#pageSize").val());
    data.pageNum = $.trim($("#pageNum").val());
    $.ajax({
        url:'/back/news/findAll',
        data:data,
        type:'post',
        dataType:'json',
        success:function (data) {
         showNews(data.list);
         $("#pageCount").html(data.number)
        }
    })
}
//页面展示格式
function showNews(data) {
    let html = "";//进行字符串拼接
    for (let i = 0; i < data.length; i++) {
        html += ' <tr>\n' +
            '      <td>' + data[i].id + '</td>\n"' +
            '       <td>' + data[i].newsType + '</td>\n' +
            '        <td>' + data[i].newsTitle + '</td>\n' +
            '        <td>' + data[i].publisher + '</td>\n' +
            '        <td>' + data[i].newsContent + ' </td>\n' +
            '        <td>' + data[i].releaseTime + '</td>\n' +
            '        <td><a  href="javascript:edit( ' + data[i].id + ')">编辑</a> <a  href="javascript:del( ' + data[i].id + ')">删除</a></td>\n' +
            '    </tr>';
    }
    $("#newsFindAll").html(html)//对当前的tbody进行赋值
}
// 编辑
function edit(id) {
    localStorage.setItem("newsId", id);
    //sessionStorage.setItem("userId",id);   本地存储  两种方式都可以
    $('#right').load('/back/news/newsEdit.html');//页面跳转
}
//删除
function del(id) {
    $.ajax({
        url: '/back/news/delete',
        data: {id: id},
        type: 'get',
        dataType: 'json',
        success: function (data) {
            if (data.result === 1) {
                $('#right').load('/back/news/newsManage.html');
            } else {
                alert("删除失败");
            }
        }

    })
}